import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";

const meshGroup = new THREE.Group();
const loader = new GLTFLoader();
loader.load("/assets/model/Horse.gltf", function (gltf) {
	console.log(gltf.scene);
	gltf.scene.scale.set(50, 50, 50);
	meshGroup.add(gltf.scene);

    gltf.scene.traverse((child) => {
        if (child.isMesh) {
            if(child.name === "Cylinder") {
                child.material.color = new THREE.Color('white');
            }else if(child.name === "Cylinder_1") {
                child.material.color = new THREE.Color('pink');
            }
        }
    })

    const mixer = new THREE.AnimationMixer(meshGroup);
    // gltf.animations里保存了多个动画，可以播放任意一个
    const clipAction = mixer.clipAction(gltf.animations[0]);
    clipAction.play();

    const clock = new THREE.Clock();
    function animate() {
        const delta = clock.getDelta();
        mixer.update(delta);
        requestAnimationFrame(animate);
    }
    animate();

});


export { meshGroup };
